                        Wise Moves

           Michael Spencer shows us some ways of
          getting things moving around the screen.

Animation is the process that puts life into computer
games, but has far wider uses. The ability of a computer to
create, move and display visual information has only
reached the home market fairly recently, and is becoming a
very popular and interesting application for users at all
levels.
   Computer graphics is a term that means different things
to different people, but generally covers images that are
computer generated, modified, stored and displayed but need
not necessarily be animated. To a businessman, 'graphics'
means histograms, graphs and other methods of presenting
financial information visually; to a railway signalman the
mimic display showing train moves is a form of computer
graphic; to a student pilot on an aircraft simulator the
realistic images are computer generated. Computer aided
design perhaps involves the most complicated imagery of
all, think about car design as an example. A good deal of
computer graphics is merely static images that can be dis-
played when required, animation is the art of making those
images appear to move in such a way that the impression of
a lifelike object is created. Animation is an art that pre-
dates the computer revolution by quite a long time and its
application is a practised skill. Cartoons are a much loved
example of film animation and such films have given plea-
sure to millions, but few of these millions have ever given
much thought to the sheer effort involved in producing
those cartoons. In one second of film there will be twenty
four frames and each frame is an individual picture showing
a stage in the motion of the animated object. It doesn't
take much mental arithmetic to work out how many individual
pictures there are likely to be in a ten minute cartoon
feature.
   Cartoons are an example of drawn animation that uses the
skill of an animator to draw a sequence of individual
pictures which, when filmed, give the impression of motion.
There are other techniques of animation - model, cutout and
rostrum (controlled camera) animation are examples. These
techniques are more suitable to the use of computers to aid
such activity, drawn animation is more directly applicable
to using computers to replace manual techniques and this is
the main topic of discussion here.
   Animators in the film inductry are skilled people and
the success of the work depends on their grasp of two
factors - timing and realism. Correct timing can convey the
impression of animation well and that timing ought to re-
flect the behaviour in the real world of the object being
animated. Realism ensures that the object and its behaviour
reflect the laws of motion and the presence of gravity.
These techniques have been built up over many years and it
is only their application in the use of computers that is
new - the computer screen is only another medium on which
to display images (it may be called electronic paper). The
computer may also be a means to an end, computers as 
animators' tools are having an impact on the film industry.
Remember the Walt Disney film TRON about a computer pro-
grammer and his battle against a wayward super computer? A
good deal of that film was made by using computer animation
and still graphics - anovel approach that created a stun-
ning impact. Computers can take the edium out of the
process of producing images for animation - a single image
can be manipuplated to a new position, size or shape by
applying mathematical routines. Taken to an extreme it may
be possible to produce a complete film in a few years time,
and indeed a Hollywood film company is using a CRAY super
computer to cope with the fantastic number of calculations
involved in such processes. This machine made its debut
code cracking in America for the Government and has since
made contributions in many other fields.
   Animation itself involves three basic processes - pre-
paration of the image, manipulation and display. It is the
manipulation that is at the heart of the technique of
animation. The computer offers the electronic paper for us
to exploit and the characteristics of that paper determine
what sort of animation is possible. There are three sorts
of graphics that can be created on most home computers -
block, pixel and line graphics. Block graphics involve the
use of character sized shapes (see the top row of the
Spectrum keyboard) which may be used individually or as
part of larger shapes which can be moved around the screen.
The program in figure one [called "Block" on the TZX which
goes with this article] creates such a shape and moves it
around. The program is reasonably effective and shows some
of the basics of simple animation. An image drawn on the
screen is erased and a new image created in a different
place which gives the appearance of motion. A variation of
the technique would be to surround the image with blank
characters to erase parts of the old image at each move.
If no blanking took place - using either method - then the
effect would be spoiled by the image leaving a visible
trail, the image is being drawn and redrawn to the same
piece of electronic paper. The technique is summed up as
draw, wait, erase and redraw. Block graphics are useful but
a little boring, so fortunately we have access to pixel
graphics.

 Pixels

Pixel graphics are much simpler for they are single points
on the screen that can be turned on and off and, most
importantly, their state may be tested. Pixel graphics
introduce the idea of resolution - the higher the resolu-
tion (the number of pixels in a given area) the better the
image. The Sinclair Spectrum has a very reasonable resolu-
tion of 176 by 256 pixels each of which can be individually
set and tested. In case of a single pixel being moved
around the screen the technique is similar to block graph-
ics, the pixel set and unset (erased) and moved to a new
position after appropriate delay. Groups of pixels make up
the high resolution screens that form the bulk of a com-
puter game's attractions. These shapes can be animated by
dealing with the individual pixels that make them up.
Collision detection is a computer inspired technique where
the collision between two objects on the screen can be
detected and the appropriate action taken. Shapes can be
made to rebound from obstacles, a method used to great
effect in bat and ball games. Collisions can lead to explo-
sions which is again a widely used technique in the most
popular arcade games. The program in figure two ["Pixel"
on the TZX] illustrates pixel animation and collision
detection.
   Some computers support Sprite graphics, unfortunately
the Spectrum does not, although some users have managed to
write interrupt driven software that gives a fair implemen-
tation of this feature which is normally supported by a
dedicated chip. A Sprite is a shape that is defined and
moved around the screen by dedicated software, and usually
supports full collision detection. The program in figure
two has simple collision detection where the place the
pixels will occupy next is tested to see if it is possible
to move there. A realistic rebound is programmed in rather
than a straight reversal of course if a collision is
detected.

 Lines

Line graphics can be the most satisfying because they can
be used to make up wire images of objects, giving a three
dimensional effect. That object can be moved realistically
around the screen and even rotated around various points.
Wire images have been used in some computer games but are
probably best known in such applications as building and
car design. The program in figure 3 ["Cuboid" on the TZX]
is an example. These are the three main ways of producing
graphics on most home computers and fortunately we have
access to all three on the Sinclair Spectrum. It has to be
said that the best animation on the Spectrum will be writ-
ten using machine code rather than BASIC because machine
code is a good deal faster. BASIC is easy to understand,
and has been used in the examples here for clarity, though
it can cause flickering and other odd effects and detract
from the effect that you are trying to achieve.
   The actual process of animation on computers is a good
deal different from that using hand drawn images and film.
A computer really only understands numbers, so that images
shown have to be digitised to coordinates and these coor-
dinates manipulated to produce new images in different
positions. Do that quickly enough and you have animation.
In extreme cases a single drawing may be made and many
different images made by mathematical manipulation. For
example, an image may be made wider or taller by altering
values along one axis, give a computer two images, one
bigger than the other and the computer can be programmed to
produce a new image between the two sizes - this is known
as in-betweening. Animation implies change, so that images
presented sequentially appear to move. The basis of anima-
tion involves a number of key elements that help produce
the desired effect. The obvious is change in size or shape,
others include change in speed, angle, colour, position and
perspective - remember these are animation techniques and
not computer techniques. We have all seen some really funny
cartoons where some of the humour has been about the
ability of a character or object to survive impossibly
destructive situations - for example holding a bomb when it
goes off, being squashed flat or stretched. Twist, skew,
shear, bend and explode can all be used to great effect.
Explosions seem to characterise the ever popular arcade
game and it is worth knowing how to do this.

 Bang!

The basis of an explosion effect is that the image breaks
up and moves apart from a central point. The image is
initially chopped or minced into short lines or pieces and
these move radially out from a central point. Most explo-
sions are a variation of this, for example the bits of the
exploded image can be made to tumble, flicker or leave
trailing images as it moves apart. The image may be explo-
ded into single pixels that change colour rapidly as they
move outwards. A computer can generate useful sound effects
to accompany this visual extravaganza which makes the whole
process more effective.
   Manipulation in size is one technique that a computer
can do quickly without the need for new images to be drawn,
digitised and stored. It is simply a matter of arithmetic
to alter the size of an object. For example characters can
be made larger by scanning the character square and repro-
ducing the image larger or smaller. The program in figure
four ["Double"] does this for one character and displays an
image twice the size at a different place on the screen. It
achieves this by scanning all the sixty four pixels in the
character square and displaying them doubled up on both
axes. It is a simple matter to adapt this program to repro-
duce a character that is stretched taller or wider by only
adjusting the values on one or the other axis. This
technique, because it works at the pixel level, will also
expand any shape. In BASIC it is rather slow, in machine
code it is much faster and can be used to great effect.
   Perhaps the most exciting possibility for a home com-
puter user is to make use of line graphics and produce a
three-dimensional representation of an object that can be
rotated in any given direction and create some illusion of
movement. The wire frame image depends on coordinate geo-
metry to manipulate it, it is a matter of numbers and few
rules. The biggest problem is that the television or other
computer screen is only two-dimensional. Perhaps one day
hologram technology will have advanced enough so that
three-dimensional images can be projected into a living
room like a super television, but until then we must rely
on the eye being fooled by two-dimensional trickery. Per-
spective drawings do this and the Renaissance artists were
masters of the art and produced some remarkable paintings
and drawings. The keys to such works of art is the 'vani-
shing point'. Looking along railway lines, the tracks
appear to converge at a point - this is a vanishing point.
These drawings are made with reference to such a point
which is often off the paper.

 3D

In three-dimensional reality we can describe an object by
reference to three axes - x, y and z as they are conventio-
nally known. When measuring an object we normally describe
the dimensions in terms of length, width and height, but in
order to describe an object in terms suitable for computer
graphics we must describe the object in distances from an
origin point. The origin can be a corner of the object
itself or further away, the object may be viewed from the
origin or another point. This introduces the idea of how we
can make a flat two-dimensional representation appear
three-dimensional and provide the basis for animating such
an object. The diagram in figure 5 [which you should find
accompanying this text, as "Wise Moves.png"] shows how a
single point viewed from the origin of the coordinates
(x, y and z) can be represented on the picture plane at a
set distance from the viewpoint. The picture plane of
course is our television screen and the x and y coordinates
of the point on it with respect to the bottom left hand
corner are calculated as x times (distance of picture plane
to viewpoint axis divided by z). This is called transfor-
ming and is good for any object where the viewpoint and the
origin of the coordinate system are the same place.
   Some degree of animation is now possible once the three
dimensions are transformed into two on the picture plane.
The x,y coordinates can be transformed around the screen -
enlarged, reduced, moved or rotated and the perspective
altered by shifting the picture plane. Rotation presents an
interesting problem because one has to resort to sines and
cosines to solve the shifting of x and y coordinates about
the centre of rotation. Taking and anti-clockwiser rotation
through a specified angle, A, then the new coordinates of
the point x,y will be calculated as x cosine A - y sine A
for the x coordinate, and x sine A + y cosine A for the y
coordinate. This idea is incorporated into the program in
figure 6 ["Rotation"] which draws a cube then rotates it
into a new position.
   Line graphics are particularly suitable for these sorts
of transformation, though it must be said that the mathe-
matics can become quite complex when trying to view the
object from any point other than the origin of the coor-
dinate system. Naturally for flicker free animation machine
code is essential as there may be a large number of calcu-
lations involved in transforming each point on an object.
Combinations of block, pixel and line graphics can be seen
in many animated computer games as well as more serious
applications but it must be said that really complex
animation is the preserve of much larger and more expensive
computers. What is needed in the home computer market is
dedicated software that will allow easy and fast animation
by coping with the transformations necessary, the software
can be rather like the sprite graphics support available on
a chip in some computers.